<?php
/**
 * Created by PhpStorm.
 * User: lvshuyun
 * Date: 2015/6/9
 * Time: 10:56
 */

namespace common\models\DAO;


use yii;
use yii\db\ActiveRecord;

class AdminRole extends ActiveRecord {

    public static function tableName()
    {
        return '{{%admin_role}}';
    }

    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'roleName' => '角色名称',
            'agentID' => '代理ID'
        ];
    }

    public function rules(){
        return [
            ['roleName', 'required'],
        ];
    }

    public function scenarios()
    {
        return [
            'default' => [],
            'add' => ['roleName', 'agentID'],
            'edit' => ['roleName', 'agentID'],
        ];
    }

    public function getAgent(){
        return $this->hasOne(Agent::className(), ['id'=>'agentID']);
    }

    public function getAdminPower(){
        return $this->hasMany(AdminRole::className(), ['id'=>'powerID']);
    }

    public function getAdmin(){
        return $this->hasMany(Admin::className(), ['id'=>'roleID']);
    }

    public static function getSelectList()
    {
        $list = self::find()->where('id>1')->asArray()->all();
        return yii\helpers\ArrayHelper::map($list, 'id', 'roleName');
    }

}